import React, { useEffect } from 'react';
import { View, ActivityIndicator } from 'react-native';
import { router } from 'expo-router';
import { useAppDispatch, useAppSelector } from './store/hooks';
import { getCurrentUser } from './store/userSlice';

export default function Home() {
  const { isAuthenticated, loading } = useAppSelector(state => state.user);
  const dispatch = useAppDispatch();

  useEffect(() => {
    // 尝试获取当前用户信息
    dispatch(getCurrentUser())
      .unwrap()
      .then(() => {
        // 登录成功，跳转到主页tabs
        router.replace('/(tabs)');
      })
      .catch(() => {
        // 获取用户信息失败，跳转到登录页
        router.replace('/login');
      });
  }, [dispatch]);

  // 显示加载指示器
  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <ActivityIndicator size="large" color="#5e35b1" />
    </View>
  );
} 